/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.font;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.font
 * @date 05/02/2014 - 22:20:23
 */
public class MyFont extends Font {
	
	private static final long serialVersionUID = -5167250790751589946L;
	
	/**
	 * @param myFont
	 */
	protected MyFont(final Font myFont) {
	
		super(myFont);
	}
	
	/**
	 * @param attributes
	 */
	public MyFont(final Map<? extends Attribute, ?> attributes) {
	
		super(attributes);
	}
	
	/**
	 * @param fontName
	 * @param isPlain
	 * @param isItalic
	 * @param isBold
	 * @param size
	 */
	public MyFont(final String fontName, final boolean isPlain, final boolean isItalic, final boolean isBold, final int size) {
	
		super(makeFont(fontName, isPlain, isItalic, isBold, size));
	}
	
	/**
	 * @param name
	 * @param style
	 * @param size
	 */
	public MyFont(final String name, final int style, final int size) {
	
		super(name, style, size);
	}
	
	/**
	 * @return fonts available
	 */
	public static List<Font> getFontsAvailable() {
	
		final List<Font> fonts = new ArrayList<>();
		
		//
		for(final String fontName : getSystemFontNames()) {
			
			final Font font = new Font(fontName, PLAIN, 12);
			
			// Se a Font pode ser utilizada visualmente pelo Java
			if(font.canDisplayUpTo("A") == -1) {
				
				fonts.add(font);
			}
		}
		
		return fonts;
	}
	
	/**
	 * @return fontStyles[]
	 */
	public static FontStyle[] getFontStyles() {
	
		return FontStyle.values();
	}
	
	/**
	 * @return fontNames[]
	 */
	public static String[] getSystemFontNames() {
	
		return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
	}
	
	/**
	 * @param fontName
	 * @param isPlain
	 * @param isItalic
	 * @param isBold
	 * @param size
	 * @return java.awt.Font
	 */
	public final static Font makeFont(final String fontName, final boolean isPlain, final boolean isItalic, final boolean isBold, final int size) {
	
		Font myFont = null;
		
		//
		if(isPlain) {
			
			//
			if(isItalic) {
				
				myFont = new Font(fontName, Font.PLAIN | Font.ITALIC, size);
				
			}else {
				
				myFont = new Font(fontName, Font.PLAIN, size);
			}
			
		}else {
			
			//
			if(isBold) {
				
				//
				if(isItalic) {
					
					myFont = new Font(fontName, Font.BOLD | Font.ITALIC, size);
					
				}else {
					
					myFont = new Font(fontName, Font.BOLD, size);
				}
			}
		}
		
		return myFont;
	}
}
